package com.ph.shopping.facade.member.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.ph.shopping.common.util.container.ParamVerifyUtil;
import com.ph.shopping.common.util.result.Result;
import com.ph.shopping.facade.duboresult.DubboResult;
import com.ph.shopping.facade.member.dto.MemberIntegralDto;
import com.ph.shopping.facade.member.service.IMemberIntegralService;
import com.ph.shopping.facade.member.service.dbservice.facade.IMemberIntegralDbService;

/**
 * 
 * @ClassName: MemberIntegralService
 * @Description: 会员积分
 * @author tony
 * @date 2017年3月23日
 *
 */
@Component
@Service(version = "1.0.0")
public class MemberIntegralService implements IMemberIntegralService {

	private static final Logger log = LoggerFactory.getLogger(MemberIntegralService.class);

	@Autowired
	private IMemberIntegralDbService memberIntegralDbService;

	@Override
	public Result getMemberIntegralInfoLsitByPage(MemberIntegralDto dto) {
		log.info("根据分页信息获取会员积分列表参数,MemberIntegralDto ={} ", JSON.toJSONString(dto));
		Result result = DubboResult.getDefResult();
		try {
			String[] fields = { "pageNum", "pageSize", "memberId" };
			if (ParamVerifyUtil.entityIsNotNullByField(dto, fields)) {
				result = memberIntegralDbService.queryMemberIntegralInfoLsitByPage(dto);
			}
		} catch (Exception e) {
			result = DubboResult.getResultByError(result);
			log.error("根据分页信息获取会员积分列表信息错误", e);
		}
		return result;
	}

	@Override
	public Result getMemberIntegralInfoList(MemberIntegralDto dto) {
		log.info("获取会员积分列表参数,MemberIntegralDto = {} ", JSON.toJSONString(dto));
		Result result = DubboResult.getDefResult();
		try {
			String[] fields = { "memberId" };
			if (ParamVerifyUtil.entityIsNotNullByField(dto, fields)) {
				result = memberIntegralDbService.queryMemberIntegralInfoList(dto);
			}
		} catch (Exception e) {
			log.error("查询会员积分列表数据错误", e);
			result = DubboResult.getResultByError(result);
		}
		return result;
	}

	@Override
	public Result getMemberIntegralSource() {
		Result result = DubboResult.getDefResult();
		try {
			result = memberIntegralDbService.queryMemberIntegralSource();
		} catch (Exception e) {
			log.error("查询会员积分来源字典数据错误", e);
			result = DubboResult.getResultByError(result);
		}
		return result;
	}

}
